
//imports



import {rank} from '../../templates/canvas.js'





/**
 * Product Page Config Object
 */
const pageConfig = ( {
// let pageConfig = {
  /**
   * Data Object
   */
  data: {
    homeData:'',
    imgSRC:'',
    readmore:"false"
  },

  onLoad: function (options) {
    let _this=this;
   wx.getStorage({
     key: 'productData',
     success: function(res) {
      res.data.score.expert_scores.forEach(item =>{
      item.readmore=false
      });
       _this.setData({
         homeData:res.data
       })
     },
   })
    
   
  },
  onReady:function(){
    let _this=this;

    console.log(this.data.homeData)
    
    rank('rank', this.data.homeData.score.averageScore).then(res =>{
    _this.setData({
      imgSRC:res
    })
    })
  },
  readMore(e){
    if (e.currentTarget.dataset.type == "true" || e.currentTarget.dataset.type == "false"){
    this.setData({
      readmore:this.data.readmore=='false'?'true':'false'
    })
    };
  let ID=e.currentTarget.dataset.type;
  let data = this.data.homeData.score.expert_scores;
  data.forEach((item,index)=>{
    if(item.id == ID){
      item.readmore=!item.readmore
    }
  })

  this.setData({
    ['homeData.score.expert_scores']: data
  })
  }

});



Page(pageConfig);
